#pragma once
#ifndef GAME_COMPONENT_H
#define	GAME_COMPONENT_H

#include<vector>
#include<map>
#include<fstream>

#include<AlphaTools.h>

enum componentProperties{
							POSITIONED = 0,
							VIEWABLE ,
							TOUCHABLE,
							COLLECTOR,
							COMBATANT,
							MOVEABLE,
							INTELLIGENT
							};


class GameComponent
{
public:
	std::vector<GameComponent*>		my_components;
	std::vector<componentProperties> properties;
	int num_properties;
	int num_components;
	
	inline void update(GameComponent* parent)
	{
		this->updateMe(parent);
		this->updateChildren(this);
	}
	inline virtual void updateMe(GameComponent* parent){};
	inline void updateChildren(GameComponent* parent)
	{
		for (unsigned int i = 0; i < my_components.size(); i++)
		{
			my_components[i]->update(this);
		}
	}
	
	inline void render(AlphaMatrixStack* mv, AlphaMatrix* proj)
	{
		this->renderMe(mv, proj);
		this->renderChildren(mv, proj);
	} 
	inline virtual void renderMe(AlphaMatrixStack* mv, AlphaMatrix* proj){};
	inline void renderChildren(AlphaMatrixStack* mv, AlphaMatrix* proj)
	{
		for (unsigned int i = 0; i < my_components.size(); i++)
		{
			my_components[i]->render(mv, proj);
		}
	};

	inline void init(GameComponent* parent){initMe(parent); initChildren(this);}
	inline virtual void initMe(GameComponent* parent){};
	inline void initChildren(GameComponent* me)
	{
		for (unsigned int i = 0; i < my_components.size(); i++)
		{
			my_components[i]->init(me);
		}
	}

	GameComponent();
	GameComponent(char* fname);
	~GameComponent();

	inline int getNumC(){return my_components.size();}

	inline GameComponent* getComponent(int i){return my_components[i];}

	inline void setProperties(componentProperties p)
	{
		properties.push_back(p);
	}

	inline bool checkProperties(componentProperties p)
	{
		for(int i = 0; i < num_properties; i++)
		{
			if(p == properties[i])
			{
				return true;
			}
		}
		return false;
	}

	friend bool operator<( GameComponent& q1,  GameComponent& q2)
	{
		// Check x axis
		//if(q1.getPos().getX() < q2.getPos().getX())
		//{
		//	return true;
		//}
		//if(q1.getPos().getX() > q2.getPos().getX())
		//{
		//	return false;
		//}

		//// Check y axis
		//if(q1.getPos().getY() < q2.getPos().getY())
		//{
		//	return true;
		//}
		//if(q1.getPos().getY() > q2.getPos().getY())
		//{
		//	return false;
		//}

		//// Check z axis
		//if(q1.getPos().getZ() < q2.getPos().getZ())
		//{
		//	return true;
		//}
		return false;
	}
};



#endif